package org.belkodevelop.form;

import org.belkodevelop.announcement.domain.OperationEnum;
import org.belkodevelop.announcement.service.FindRequest;
import org.belkodevelop.geocoding.adress.json.GoogleAdress;
import org.belkodevelop.geocoding.adress.json.parser.GoogleAdressConverter;
import org.belkodevelop.realty.factory.RealtyEnum;

public class FindRequestForm {

    private static String ANY_TYPE_REALTY = "ANY";

    private String adress;
    private String type;
    private String operation;
    private Double priceTo;
    private Double priceFrom;
    private GoogleAdress googleAdress;
    private Integer page;

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public Double getPriceTo() {
        return priceTo;
    }

    public void setPriceTo(Double priceTo) {
        this.priceTo = priceTo;
    }

    public Double getPriceFrom() {
        return priceFrom;
    }

    public void setPriceFrom(Double priceFrom) {
        this.priceFrom = priceFrom;
    }

    public GoogleAdress getGoogleAdress() {
        return googleAdress;
    }

    public void setGoogleAdress(GoogleAdress googleAdress) {
        this.googleAdress = googleAdress;
    }

    public FindRequest getFindRequest() {
        FindRequest findRequest = new FindRequest();
        findRequest.setType(ANY_TYPE_REALTY.equals(getType()) ? null : RealtyEnum.valueOf(getType()));
        findRequest.setPriceFrom(getPriceFrom());
        findRequest.setPriceTo(getPriceTo());
        findRequest.setCompositeAdress(GoogleAdressConverter.getCompositeAdress(getGoogleAdress()));
        findRequest.setOperationEnum(OperationEnum.valueOf(operation));
        return findRequest;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }
}
